package 栈和队列.栈实现队列;

import java.util.Stack;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/3/1 21:17
 * @description:  剑指offer题目
 * @version:
 */
public class CQueue {
    Stack<Integer> inStack ;
    Stack<Integer> outStack ;
    public CQueue() {
        inStack = new Stack<>();
        outStack = new Stack<>();
    }

    public void appendTail(int value) {
        inStack.push(value);
    }

    public int deleteHead() {
        //先进行一个判空操作，因为不排除连续出队操作
        if (outStack.isEmpty()){
            while (!inStack.isEmpty()){
                outStack.push(inStack.pop());
            }
        }
        return outStack.isEmpty() ? -1 : outStack.pop();
    }
}
